<?php
namespace Admin\Controller;
use Think\Controller;
class VideoController extends Controller {
    public function VideoList(){

        // $m_id = $_GET['m_id'];

        $videosModel = M('videos');
        $videos = $videosModel -> order("video_id")->select();
         $this->index=$videos;
        // dump($masters);
        $this->display();
    
    }

    public function delvideo($video_id){
    $videosModel=M('videos'); 
    //where实在构建条件
    if (false!==$videosModel->where("video_id=$video_id"/*必须是双引号*/)->delete()) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }

    }

     public function addVideo()
  {
    if(IS_POST)
    {
      
      $data['video_title'] = I('post.video_title');
      $data['video_intro'] = I('post.video_intro');
      
      $data['video_videos'] = I('post.video_videos');
      $data['video_time'] = I('post.video_time');
      
      
      if(empty($data['video_title']))
      {
        $this->error('视频名必须填写');
      }
      elseif(empty($data['video_intro']))
      {
        $this->error('视频简介必须填写');
      }
      else
      {
        $data['video_intro'] = md5(md5($data['video_intro']) );
        
        $videos = M('videos');
        if($_FILES['file']['error']==0 ){
            $info=$this->upload();
            $name=$info["file"]["savename"];
        }
        else{
            $name="default.jpg";
        }
        if($videos->create()){
            $videos->video_pic1=$name; 
            if(false!==$videos->add())
                      {
                $this->success('添加成功!','VideoList');
            }
            else{$this->error('添加失败');}
        }else{
            $this->error($videos->getError());
        }
      }
    }
    else
    { 
      $this->display();
    }    

  }
   public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('avi', 'wmv', 'asf');// 设置附件上传类型
        $upload->rootPath  =     'C:\Users\dell\Desktop\新建文件夹'; // 设置附件上传根目录  //  
        $upload->autoSub = false;//关闭子目录，默认true
        $upload->savePath  =     ''; // 设置附件上传(子)目录，默认目录名为年月日
        $info   =   $upload->upload();  // 上传文件 
        if(!$info) {
            $this->error($upload->getError());    
        }
        else{
            return $info;
        }                    
    }
    


     


}
?>